package com.liangsui.mss.controller.system;

import com.liangsui.mss.aspectj.Log;
import com.liangsui.mss.aspectj.enums.BusinessType;
import com.liangsui.mss.dto.CheckItemDto;
import com.liangsui.mss.service.CheckItemService;
import com.liangsui.mss.utils.ShiroSecurityUtils;
import com.liangsui.mss.vo.AjaxResult;
import com.liangsui.mss.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * CheckItemController
 *
 * @author zhangjiawei
 * @email 1533167396@qq.com
 * @date 2022/12/5 23:44
 */
@RestController
@RequestMapping("system/checkItem")
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;

    /**
     * 分页查询
     */
    @GetMapping("listCheckItemForPage")
    public AjaxResult listCheckItemForPage(CheckItemDto checkItemDto) {
        DataGridView gridView = this.checkItemService.listCheckItemPage(checkItemDto);
        return AjaxResult.success("查询成功", gridView.getData(), gridView.getTotal());
    }

    /**
     * 查询全部可用的检查项目
     *
     * @return
     */
    @GetMapping("selectAllCheckItem")
    public AjaxResult selectAllCheckItem() {
        return AjaxResult.success(this.checkItemService.selectAllCheckItem());
    }

    /**
     * 添加
     */
    @PostMapping("addCheckItem")
    @Log(title = "添加通知检查项目", businessType = BusinessType.INSERT)
    public AjaxResult addCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.checkItemService.addCheckItem(checkItemDto));
    }

    /**
     * 修改
     */
    @PutMapping("updateCheckItem")
    @Log(title = "修改检查项目", businessType = BusinessType.UPDATE)
    public AjaxResult updateCheckItem(@Validated CheckItemDto checkItemDto) {
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(this.checkItemService.updateCheckItem(checkItemDto));
    }


    /**
     * 根据ID查询一个通知检查项目信息
     */
    @GetMapping("getCheckItemById/{checkItemId}")
    public AjaxResult getCheckItemById(@PathVariable @Validated
                                           @NotNull(message = "检查项目ID不能为空") Long checkItemId) {
        return AjaxResult.success(this.checkItemService.getCheckItemById(checkItemId));
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteCheckItemByIds/{checkItemIds}")
    @Log(title = "删除检查项目", businessType = BusinessType.DELETE)
    public AjaxResult deleteCheckItemByIds(@PathVariable @Validated
                                               @NotEmpty(message = "要删除的ID不能为空") Long[] checkItemIds) {
        return AjaxResult.toAjax(this.checkItemService.deleteCheckItemByIds(checkItemIds));
    }
}
